// page p0004 controller
var p0004Controller = (function($) {

	var key = 'p0004';
	var selector = '#' + key;
	var page = 'pages/' + key + '.html';
	var tryCount = 0;

	var draw = function (item) {
		if (!$.esPage.queryParams)
			return;
	};

	var showDialog = function (callback, queryParams) {
		$.esPage.showDialog(selector, {
			callback: callback,
			queryParams: queryParams
		});
		app.afterLoad(selector);
		$('#p0004Password').focus();
	};

	var obj = {

		init: function (callback) {
			app.loadPage(page, function () {
				$(selector).esPage();
				if (callback)
					callback();
			});
		},

		refresh: draw,
		showDialog: showDialog,

		btnLoginClick: function () {
			var password = $('#p0004Password').val();
			PlatformSupport.checkPassword(password, function (currect) {
				if (!currect) {
					if (tryCount >= 2)
						$.esPage.closeDialog(true);
					else
						alert('错啦! 还剩 ' + (2-tryCount) + ' 次机会');
					tryCount++;
					return;
				}

				$.esPage.closeDialog(false);
			});
		},

		btnCancelClick: function () {
			$.esPage.closeDialog(true);
		}
	};

	app.registerPageController(key, obj);

	return obj;

})(jQuery);